﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace NLUNZ
{
    public partial class GetTrackingData : System.Web.UI.Page
    {
        private static string webServiceUrl = @"http://api.kuaidi100.com/api?id={0}&com={1}&nu={2}&show=0&muti=1&order=asc";
        private static string apiKey = "fc8c15ca124131c7";
        protected void Page_Load(object sender, EventArgs e)
        {
            string code = Request.QueryString["code"];
            string trackingNumber = Request.QueryString["trackingNumber"];
            Response.Write(FindTracking(code,trackingNumber));
        }

        public string FindTracking(string code, string trackingNumber)
        {
            
            string url = string.Format(webServiceUrl, apiKey, code, trackingNumber);

            WebResponse response;
            try
            {
                WebRequest request = WebRequest.Create(url);
                response = request.GetResponse();
            }
            catch (Exception ex)
            {
                return ex.Message + ex.StackTrace;
            }
            Stream stream = response.GetResponseStream();

            StreamReader reader = new StreamReader(stream);
            //string json = reader.ReadToEnd();
            return reader.ReadToEnd();
        }
    }
}